//
// Created by root on 17-7-14.
//


#include "../include/communication.h"


int main()
{
    int i = 1000;

    int Listener = 0;
    do {
        Listener = listenOn(9001);
        if (Listener < 0) {
            fprintf(stderr, "Master cannot listen on, retry in 3s!\n");
            std::this_thread::sleep_for(std::chrono::seconds(3));
        }
    } while (Listener < 0);
    fprintf(stdout, "Listening!\n");
    int nsock = acceptAt(Listener);
    fprintf(stdout, "Accept acommplished\n");
    while(1){
        char s[5];
        readUntil(nsock, s, 5);
        printf("%s\n", s);
        std::this_thread::sleep_for(std::chrono::seconds(3));
        i--;
    }


}
